package com.boost.tjvm.invoke;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

public class MethodHandleTest {
    static class ClassA{
        public void println(String s){
            System.out.println(s);
        }
    }

    public static void main (String [] args) throws Throwable{
        //Object o= System.out;
        Object o= new ClassA();
        getPrintlnMh(o).invokeExact("icyfenix");
    }

    private static MethodHandle getPrintlnMh(Object reveiver) throws Throwable{
        /**
         * 第一个参数是返回值
         * 第二个参数是方法具体参数
         */
        MethodType mt = MethodType.methodType(void.class,String.class);

        return MethodHandles.lookup().findVirtual(reveiver.getClass(),"println",mt).bindTo(reveiver);
    }

}
